//
//  CartPart.swift
//  Composite
//
//  Created by LY on 2017/10/26.
//  Copyright © 2017年 DesignPatterns. All rights reserved.
//

import Foundation
class CarPart:carPart{
    let name: String
    let price: Float
    
    init(name:String,price:Float) {
        self.name = name
        self.price = price
    }
}

class CarCompositePart:carPart{
    let name: String
    let parts:[carPart]
    init(name:String,parts:carPart...) {
        self.name = name
        self.parts = parts
    }
    var price: Float {
        return parts.reduce(0, { (subtotal, item:carPart) -> Float in
            return subtotal + item.price
        })
    }
}
